#!/usr/bin/python
'''
Filter a SAM file to a given list of regions.
'''
import sys
import os

# parameters.
sam_file = sys.argv[1]
filter_file = sys.argv[2]

# read in filter.
filters = {}
fin = open(filter_file, "rb")
for line in fin:
	filters[line.strip()] = True
fin.close()

# stream sam file.
fin = open(sam_file, "rb")
for line in fin: 
	# skips.
	if line[0] == "@": continue
	
	# split.
	tmp = line.split("\t")
	
	# check against filter.
	if tmp[2] in filters:
		print line.strip()

fin.close()
